if(window.jQuery && window.jQuery.PPF && !window.jQuery.PPF.kaoshiview) {
	(function($){
		$PPF.extend({
			kaoshiview : {
				data: []
				,kjdata: {}
				,sjdata: {}
				,stypes: {}
				,config: function( param ){
				this.stypes = typeof param.stypes == "object" ? param.stypes : {};
					this.sjdata = typeof param.sjdata == "object" ? param.sjdata : {};
					this.kjdata = typeof param.kjdata == "object" ? param.kjdata : {};
					for(var e in this.kjdata.stdata) {
						this.data[this.data.length] = $.extend( true,{ xtid: e },this.kjdata.stdata[e] );
					}
					this.initThao();
					this.daan = $.extend( true,{},this.kjdata.daandata );
				}
				,init: function(){
					var data = this.data;
					$("#kaoshiEtemList").empty();
					for(var i=0; i < data.length; i++){
						this.appendShiti( data[i] );
					}
					$(".shitiContain li").removeAttr('onmouseout').removeAttr('onmouseover');
				}
				,initThao: function(){	//初始化题号
					var th = 1;
					for(var id in this.sjdata.d_dlmix){
						for(var i=0;i<this.data.length;i++){
							if(this.data[i].did == id) {	//todo 考虑组合题
								this.data[i].thao = th++;
							}
						}
					}
				}
				,appendShiti: function( data ){
					var c=$("#_duanContainer_"+data.did);
					if(c.size() < 1) {
						var d = this.getDuanData(data.did);
						$("#kaoshiEtemList").append($("#kaoshiduan_tpl").content({
							id: d.id
							,title: d.t
							,d: d.d
						}));
						c=$("#_duanContainer_"+data.did);
					}
					$(".shitiContain",c).append( this.createShitiEtem(data) );
					this.appendrDaan( data );
				}
				,getDuanData: function(id){
					var d = this.sjdata.d_dlmix;
					if(typeof d[id] == "object"){
						var dd = d[id];
						dd.id = id;
						return dd;
					}
					return null;
				}
				,getStType: function(t){
					try{ return this.stypes[t].tixing; }catch(e){ return 'danxuan'; }
				}
				,createShitiEtem: function(data){
					var content = 'loading...';
					var title = data.title;
					var id = data.xtid;
					var _t = this;
					switch( this.getStType(data.type) ){
						case 'danxuan':
							content = PPF.html.radios({
								options: data.xx,
								checked: _t.daan[data.xtid],
								name:'st_'+id,
								_key: "k",
								_val: "xx",
								abc: true,
								label_ids: true,
								disabled: 'disabled'
							});// + '<div>&nbsp;</div>';
							var ext = "分值："+ PPF.formatFen(data.fen);
							//if(data.kf>0) 
							ext += " 答错扣" + PPF.formatFen(data.kf) + "分 ";
							title = title + "（" + ext + "）";
							break;
						case 'duoxuan':
							content = PPF.html.checkboxes({
								options: data.xx,
								checked: _t.daan[data.xtid],
								name:'st_'+id,
								noadd:true,
								_key: "k",
								_val: "xx",
								abc: true,
								label_ids: true,
								disabled: 'disabled'
							});// + '<div>&nbsp;</div>';
							var ext = "分值："+ PPF.formatFen(data.fen);
							//if(data.kf>0) 
							ext += " 答错扣" + PPF.formatFen(data.kf) + "分 ";
							//if(data.hfen>0) 
							ext += " 少选得" + PPF.formatFen(data.hfen) + "分 ";
							title = title + "（" + ext + "）";
							break;
						case 'xinli':
							var xx = {};
							for(var e in data.xx){
								var tmp = {k:data.xx[e].k,xx:data.xx[e].xx };
								xx[e] = tmp;
							}
							content = PPF.html.radios({
								options: xx,
								checked: _t.daan[data.xtid],
								name:'st_'+id,
								_key: "k",
								_val: "xx",
								abc: true,
								label_ids: true,
								disabled: 'disabled'
							});// + '<div>&nbsp;</div>';
							break;
						case 'jianda':
							content = '我的答案：' + (_t.daan[data.xtid] ? _t.daan[data.xtid] : '无');
							var ext = "分值："+ PPF.formatFen(data.fen);
							title = title + "（" + ext + "）";
							break;
					}
					return $("#shiti_tpl").content({
						title:title,
						content: content,
						thao: data.thao,
						jieda: this.sjdata.protected > 0 ? '解答保密' : "试题解答：" + data.jieda,
						daan: '',
						id: id
					});
				}
				,appendrDaan: function(data){
					var id = data.xtid;
					$("#_rdaan_"+id).html(this.getrDaan(data));
				}
				,getrDaan: function(data){
					if(this.sjdata.protected > 0) return '答案保密';
					if(this.kjdata.rdaandata){
						var id = data.xtid;
						var d = this.kjdata.rdaandata[id];
						var t = this.getStType(data.type);
						if(d || t == 'xinli'){
							switch( t ){
								case 'xinli':
									var rr = [];
									for(var e in data.xx){
										var ii = $("label[for='radios_st_"+id+"_"+data.xx[e].k+"']").children("span.pcur").html();
										rr[rr.length] = '选择<span class="pcur">'+ii+'</span>得' + PPF.formatFen(data.xx[e].fen) + '分';
									}
									return rr.join(' ');
								case 'danxuan':
									var ii = $("label[for='radios_st_"+id+"_"+d+"']").children("span.pcur").html();
									return '正确答案：<span class="pcur">'+ii+'</span>';
								case 'duoxuan':
									var rr = [];
									var ii;
									for(var e in d){
										ii = $("label[for='checkboxes_st_"+id+"_"+d[e]+"']").children("span.pcur").html();
										rr[rr.length] = '<span class="pcur">'+ii+'</span>';
									}
									if(rr.length>0){
										return '正确答案：' + rr.join('');
									}else{
										return '答案保密';
									}
									break;
								case 'jianda':
									return '正确答案：' + d;
									break;
							}
						}
					}
					return "答案保密";
				}
			}
		});
	})(jQuery);
}

jQuery(function($){
	$("#kaojuan_select").bind(
		'click',
		function(){
		PPF.shijuanview.select( $(this).attr('key') );
	});
});